// 在之前项目基础上，如果有post请求，要如何拿到请求过来的数据？请编码实现
import Koa from "koa";
import {KoaRouter,Url} from "koa-router";
import bodyparser from "koa-bodyparser"

let app = new Koa();
let router = new KoaRouter();
// 端口
const Port = 8000;
// 注册Router
{
    router.get("/", async (ctx, next) => {
        ctx.body = "首页";
    })
    router.get("/weixin", async (ctx, next) => {
        ctx.body = "微信";
    })
    router.get("/alipay", async (ctx, next) => {
        ctx.body = "支付宝";
    })
    router.get("/ds", async (ctx, next) => {
        ctx.body = "yyds";
    })
}// get for 3.

router.get("/app", async (ctx, next) => {
    // requse into to html (http://127.0.0.1:8000/app?code=66)
    ctx.response.body = ctx.request.query;
});//get for 3.4.

router.post("/post", async (ctx, next) => {
    // get request .JSON file
    const putjson = ctx.request.body;
    // into .JSON retrun html
    ctx.response.body = putjson;
})

app.use(bodyparser())

app.use(router.routes())

app.listen(Port, () => {
    console.log(`服务已在http://127.0.0.1:${Port}上运行 `);

})